namespace VegetableSale.NET.Utils;

public class RandomStringUtils
{
    private static Random random = new Random();
    /// <summary>
    /// 随机字符串
    /// </summary>
    /// <param name="chars"></param>
    /// <param name="length"></param>
    /// <returns></returns>
    public static string GetRandomStr(string chars, int length)
    {
        if (string.IsNullOrEmpty(chars))
        {
            chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghizklmnopqrstuvwxyz0123456789";
        }
        //const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        return new string(Enumerable.Repeat(chars, length)
            .Select(s => s[random.Next(s.Length)]).ToArray());
    }

}